<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <!-- 避免IE使用兼容模式 -->
    <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
    <meta name="renderer" content="webkit">
    <!--<link rel="stylesheet" type="text/css" href="/easyui/themes/metro/easyui.css"/>-->
    <!-- TopJUI框架样式 -->
    <link type="text/css" href="/topjui/css/topjui.core.min.css" rel="stylesheet">
    <link type="text/css" href="/topjui/themes/default/topjui.bluelight.css" rel="stylesheet" id="dynamicTheme"/>
    <!-- FontAwesome字体图标 -->
    <link type="text/css" href="/static/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet"/>
    <!-- layui框架样式 -->
    <link type="text/css" href="/static/plugins/layui/css/layui.css" rel="stylesheet"/>
    <link type="text/css" href="/topjui/css/myui.css" rel="stylesheet"/>
    <link rel="stylesheet" href="/static/plugins/raty/jquery.raty.css">
    <script type="text/javascript" src="/static/public/js/topjui.config.js"></script>
    <!-- layui框架js -->
    <script type="text/javascript" src="/static/plugins/layui/layui.js" charset="utf-8"></script>
    <script src="/easyui/jquery.min.js"></script>
    <script src="/easyui/jquery.easyui.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="/easyui/locale/easyui-lang-zh_CN.js" type="text/javascript" charset="utf-8"></script>
    <script type="text/javascript" src="/topjui/js/sysutils.js"></script>
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=lqVkw7DAWGt8CA9NAzxGWrQq"></script>
    <script src="/static/plugins/raty/jquery.raty.js"></script>
</head>

<body>

<table id="rowgrid" class="topjui-datagrid"></table>

<script type="text/javascript" charset="utf-8" th:inline="none">
    var listgrid;
    $(function(){
        listgrid = $('#rowgrid').datagrid({
            url:"/task/lslist",
            method:'get',
            fit : true,
            fitColumns : true,
            border : false,
            pagination : true,
            idField : 'id',
            pageSize : 20,
            pageList : [ 20, 50, 100 ],
            sortName : 'id',
            sortOrder : 'desc',
            checkOnSelect : true,
            selectOnCheck : true,
            nowrap : false,
            columns:[[
                {
                    field:'id',
                    title:'编号',
                    width:50,
                    checkbox : true
                }, {
                    field:'projectid',
                    title:'所属项目ID',
                    hidden:true
                }, {
                    field:'projectcode',
                    title:'所属项目编码',
                    width:40
                }, {
                    field:'projectname',
                    title:'所属项目名称',
                    width:60
                },{
                    field:'boardname',
                    title:'配电房名称',
                    width:60
                }, {
                    field:'voltmark',
                    title:'电压等级',
                    hidden:true
                }, {
                    field:'volume',
                    title:'电压等级',
                    hidden:true
                }, {
                    field:'usertype',
                    title:'用户类型',
                    hidden:true
                }, {
                    field:'factoryname',
                    title:'所属单位名称',
                    sortable:true,
                    width:60
                }, {
                    field:'factoryuser',
                    title:'单位负责人',
                    width:40
                }, {
                    field:'factoryphone',
                    title:'单位联系方式',
                    width:40
                }, {
                    field:'checktime',
                    title:'定时巡检日期',
                    hidden:true
                },  {
                    field:'routerid',
                    title:'所属巡视单位ID',
                    hidden:true
                }, {
                    field:'routername',
                    title:'巡视单位',
                    width:60
                }, {
                    field:'cunsumername',
                    title:'巡视人员',
                    hidden:true
                }, {
                    field:'cunsumermobile',
                    title:'巡视手机',
                    hidden:true
                }, {
                    field:'cname',
                    title:'执行人员',
                    width:40
                }, {
                    field:'cmobile',
                    title:'执行手机',
                    width:40
                }, {
                    field:'boardlng',
                    title:'配电房所在位置lng',
                    hidden:true
                }, {
                    field:'boardlat',
                    title:'配电房所在位置lat',
                    hidden:true
                }, {
                    field:'createtime',
                    title:'派单时间',
                    hidden:true
                }, {
                    field:'gettime',
                    title:'接单时间',
                    hidden:true
                }, {
                    field:'optime',
                    title:'操作时间',
                    hidden:true
                }, {
                    field:'stoptime',
                    title:'完成时间',
                    width:60
                }, {
                    field:'tasktype',
                    title:'任务类型',
                    width:40,
                    formatter:function (value,row,index) {
                        if(value == '10'){
                            return "设备操作"
                        }else if(value == '20'){
                            return "保电"
                        }else if(value == '30'){
                            return "检修"
                        }else if(value == '40'){
                            return "设备清扫"
                        }else if(value == '50'){
                            return "巡视"
                        }else if(value == '60'){
                            return "红外测温"
                        }else if(value == '70'){
                            return "开关核对"
                        }else if(value == '80'){
                            return "环境清扫"
                        }else if(value == '100'){
                            return "特巡"
                        }else if(value == '110'){
                            return "清扫"
                        }else{
                            return "需求响应"
                        }
                    }
                },{
                    field:'assess',
                    title:'任务评价',
                    width:60,
                    sortable:true,
                    formatter:function (value,row,index) {
                        if(value == '5') {
                            return "<img src='/static/admin/images/star5.png'>"
                        }else if(value=='4'){
                            return "<img src='/static/admin/images/star4.png'>"
                        }else if(value=='3'){
                            return "<img src='/static/admin/images/star3.png'>"
                        }else if(value=='2'){
                            return "<img src='/static/admin/images/star2.png'>"
                        }else if(value=='1'){
                            return "<img src='/static/admin/images/star1.png'>"
                        }else{
                            return "<img src='/static/admin/images/star0.png'>"
                        }
                    }
                }
            ]],
            toolbar:[{
                text:'查询',
                iconCls : 'fa fa-search',
                btnCls: 'topjui-btn-normal',
                handler : function() {
                    list_search();
                }
            },'-', {
                text:'导出',
                iconCls : 'fa fa-file-excel-o',
                btnCls: 'topjui-btn-normal',
                handler : function() {
                    tasklist_excel();
                }
            },'-', {
                text:'刷新',
                iconCls : 'fa fa-refresh',
                btnCls: 'topjui-btn-green',
                handler : function() {
                    listgrid.datagrid('reload');
                }
            }],
            onDblClickRow :function(rowIndex,rowData){
                list_editMapFun(rowData.id);
            }
        });
    });



    function list_editMapFun(id) {
        listgrid.datagrid('uncheckAll').datagrid('unselectAll').datagrid('clearSelections');
        $('<div/>').dialog({
            href : "/task/map",
            width : 700,
            height : 610,
            modal : true,
            title : '任务详情',

            onClose : function() {
                $(this).dialog('destroy');
            },
            onLoad : function() {
                var index = listgrid.datagrid('getRowIndex', id);
                var rows = listgrid.datagrid('getRows');
                var o = rows[index];
                $('#customerform').form('load', o);
                //运维类型
                $.ajax({
                    type:'get',
                    url:'/sys/groupsParam',
                    data:{
                        groups:'运维类型'
                    },
                    cache:false,
                    dataType:'json',
                    success:function(response){
                        console.log(response);
                        if(response.code == '200'){
                            secondDatas = response.result;
                            //遍历回传的数据添加到二级select
                            $.each(secondDatas, function(key, secondData) {
                                console.log(o.tasktype);
                                if(o.tasktype == secondData.value){
                                    var option = '<option value="'+secondData.value+'" selected>'+secondData.title+'</option>';
                                    $("#tasktype").append(option);
                                }else{
                                    var option = '<option value="'+secondData.value+'">'+secondData.title+'</option>';
                                    $("#tasktype").append(option);
                                }
                            });
                            //二级select展示
                            $("#tasktype").fadeIn("slow");
                        }
                    },
                    error:function(){
                        alert("请求失败")
                    }
                });
            }
        });
    }

    function list_search() {
        $('<div/>').dialog({
            href: '/task/lssearch',
            width: 390,
            height: 360,
            modal: true,
            title: '查询',
            buttons: [{
                text: '查询',
                iconCls: 'fa fa-search',
                btnCls: 'topjui-btn-normal',
                handler: function () {
                    var d = $(this).closest('.window-body');
                    var param = form2Json("search_form");
                    $('#search_form').form('submit', {
                        url: '/task/lslist',
                        onSubmit: function () {
                            return true;
                        },
                        success: function (result) {
                            try {
                                var r = $.parseJSON(result);
                                listgrid.datagrid({
                                    url: '/task/lslist',
                                    pagination: true,
                                    idField: 'id',
                                    pageSize: 20,
                                    pageList: [20, 50, 100],
                                    sortName: 'id',
                                    sortOrder: 'desc',
                                    queryParams: param,　　//关键之处
                                    data: r
                                });
                                d.dialog('destroy');

                            } catch (e) {
                                $.messager.alert('提示', result);
                            }
                        }
                    });
                }
            }],
            onClose: function () {
                $(this).dialog('destroy');
            }
        });
    }
    function tasklist_excel() {
        $('<div/>').dialog({
            href : '/task/lssearch',
            width: 390,
            height: 340,
            modal: true,
            title: '数据导出',
            buttons: [{
                text: '下载',
                iconCls: 'fa fa-search',
                btnCls: 'topjui-btn-normal',
                handler: function () {
                    var d = $(this).closest('.window-body');
                    var param = form2Json("search_form");
                    download('/task/lsListTaskExcel', param, 'post');
                    d.dialog('destroy');
                }
            }],
            onClose: function () {
                $(this).dialog('destroy');
            }
        });
    }
</script>

</body>
</html>